package com.docker.demo.demos.web;

import com.docker.demo.domain.User;
import com.docker.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class MyController {
    @Autowired
    private UserService userService;


    @GetMapping("/list")
    public HashMap<String, Object> list(){
        HashMap<String, Object> map = new HashMap<>();
        List<User> list = userService.list();
        map.put("data",list);
        return map;
    }

    @PostMapping("/save")
    public HashMap saveUser(@RequestBody User user){
        HashMap<String, Object> result = new HashMap<>();
        result.put("success",userService.save(user));
        return result;
    }
}
